﻿// -------------------------------------------------------------------------
//    @FileName         :    NFMatchPlayerModule.cpp
//    @Author           :    gaoyi
//    @Date             :    23-10-21
//    @Email			:    445267987@qq.com
//    @Module           :    NFMatchPlayerModule
//
// -------------------------------------------------------------------------

#include "NFCenterRegisterModule.h"

#include <NFServerComm/NFServerCommon/NFICenterServerModule.h>

NFCenterRegisterModule::NFCenterRegisterModule(NFIPluginManager* p) : NFMMODynamicModule(p)
{
}

NFCenterRegisterModule::~NFCenterRegisterModule()
{
}

int NFCenterRegisterModule::Awake()
{
	NFServerConfig* pConfig = FindModule<NFIConfigModule>()->GetAppConfig(NF_ST_CENTER_SERVER);
	CHECK_NULL_RE_VAL(0, pConfig, false);

	/*FindModule<NFIMessageModule>()->AddRpcService<proto_ff::STS_MAP_REG_RPC>(NF_ST_CENTER_SERVER, this, &NFCenterRegisterModule::OnRpcServiceMapReg);

	if (pConfig->CrossServer == false)
	{
		Subscribe(NF_ST_CENTER_SERVER, proto_ff::NF_EVENT_SERVER_REPORT_EVENT, NF_ST_CENTER_SERVER, pConfig->GetBusId(), __FUNCTION__);
	}
	else
	{
		FindModule<NFIMessageModule>()->AddRpcService<proto_ff::STS_CROSS_MAP_REG_RPC>(NF_ST_CENTER_SERVER, this, &NFCenterRegisterModule::OnRpcServiceCrossMapReg);
	}*/
	return 0;
}

int NFCenterRegisterModule::Tick()
{
	return 0;
}

int NFCenterRegisterModule::OnDynamicPlugin()
{
	return NFIModule::OnDynamicPlugin();
}

int NFCenterRegisterModule::OnExecute(uint32_t serverType, uint32_t nEventID, uint32_t bySrcType, uint64_t nSrcID, const google::protobuf::Message* pMessage)
{
	/*switch (nEventID)
	{
		case proto_ff::NF_EVENT_SERVER_REPORT_EVENT:
		{
			const proto_ff::ServerInfoReport* pEvent = dynamic_cast<const proto_ff::ServerInfoReport *>(pMessage);
			if (pEvent && pEvent->is_cross_server() && pEvent->server_type() == NF_ST_CENTER_SERVER)
			{
				//RegisterCrossMap();
			}
			break;
		}
	}*/
	return 0;
}

int NFCenterRegisterModule::OnHandleClientMessage(uint64_t unLinkId, NFDataPackage& packet)
{
	if (!m_pObjPluginManager->IsInited(NF_ST_CENTER_SERVER))
	{
		NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Center Server not inited, drop client msg:{}", packet.ToString());
		return -1;
	}

	if (m_pObjPluginManager->IsServerStopping())
	{
		NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Center Server is Stopping, drop client msg:{}", packet.ToString());
		return -1;
	}


	switch (packet.nMsgId)
	{
		default:
		{
			NFLogError(NF_LOG_DEFAULT, 0, "Client MsgId:{} Register, But Not Handle, Package:{}", packet.nMsgId, packet.ToString());
			break;
		}
	}
	return 0;
}

int NFCenterRegisterModule::OnHandleServerMessage(uint64_t unLinkId, NFDataPackage& packet)
{
	if (!m_pObjPluginManager->IsInited(NF_ST_CENTER_SERVER))
	{
		NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Center Server not inited, drop client msg:{}", packet.ToString());
		return -1;
	}

	if (m_pObjPluginManager->IsServerStopping())
	{
		NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Center Server is Stopping, drop client msg:{}", packet.ToString());
		return -1;
	}

	/*switch (packet.nMsgId)
	{
		default:
		{
			NFLogError(NF_LOG_DEFAULT, 0, "Server MsgId:{} Register, But Not Handle, Package:{}", packet.nMsgId, packet.ToString());
			break;
		}
	}*/
	return 0;
}




